
#include <project_config.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>


using namespace std;

vector<string> split_code_into_tokens(string code) {
    vector<string> tokens;
    string token = "";
    
    bool in_1 = false; // "
    bool in_2 = false; // `
    bool in_3 = false; // ;


    for(int i = 0; i < code.length(); i++) {
        char s = code[i];
        if (s == '\n' && !in_1 && !in_2 && !in_3) {
            tokens.push_back(token);
            token = "";
            continue;
        }
        else if (s == '\"' && !in_1) {
            in_1 = true;
            token += s;
            continue;
        }
        else if (s == '\"' && in_1) {
            in_1 = false;
            token += s;
            continue;
        }
        else if (s == '`' && !in_2) {
            in_2 = true;
            token += s;
            continue;
        }
        else if (s == '\'' && !in_3 && !in_2) {
            in_3 = true;
            token += s;
            continue;
        }
        else if (s == '\'' && in_3 && !in_2) {
            in_3 = false;
            token += s;
            continue;
        }
        else if (s == '`' && in_2) {
            in_2 = false;
            token += s;
            continue;
        }
        else if (s == ';' && !in_1 && !in_2 && !in_3) {
            token += s;
            tokens.push_back(token);
            token = "";
            continue;
        }
        else if ((s == '{' || s == '}') && !in_1 && !in_2) {
            token += s;
            tokens.push_back(token);
            token = "";
            continue;
        }
        
        else {
            token += s;
            if (i + 1 == code.length()) {
                tokens.push_back(token);
                break;
            }
        }
    }
    // 去除所有的空
    for (int i = 0; i < tokens.size(); i++) {
        if (tokens[i] == "") {
            tokens.erase(tokens.begin() + i);
            i--;
        }
    }

    return tokens;
}
